<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<link rel="stylesheet" href="${ctx}/jslib/layui/css/layui.css" media="all">
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript" src="${ctx}/jslib/layer/layer.js" charset="utf-8"></script>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>充值</title>
<style>
	.rechargeContent{
		margin-left:120px;
	}
	td{
		border:none;
		height:40px;
	}
	.bid{
		width:150px;
	}
	input{
		width:150px;
	}
	
	.list_wrap{
	    list-style: none;
	    margin-top: 5px;
	    padding-left: 10px;
	}
	.list_wrap li{
	    padding: 5px;
	}
</style>
<script type="text/javascript">
	//封装函数  实现强制转换成两位小数的功能
	onload = function(a){
	    var aNew;
	    var re = /([0-9]+.[0-9]{2})[0-9]*/;
	    aNew = a.replace(re,"$1");
	 	return aNew;
	};
	$(function(){
		//弹出框  判断value值不是数字时提示用户
		$("#money").blur(function(){
			var money= $("#money").val();
			var a=onload(money);
			$("#money").val(a);//强制将超过3位小数的改为2位小数
			if(isNaN(money) || money == 0){
				layer.alert("金额请填入数字且不能为0");
			};
		}); 
		//弹出框 点击确认
		$("#affirm").click(function(){
			var money=$("#money").val();
			var accountNumber=$("#accountNumber").val();
			var accountName=$("#accountName").val();
			var param={"income":money,"accountNumber":accountNumber,"accountName":accountName};
			//console.log(param);
			if(money != "" && money != 0 && isNaN(money)==false  && accountNumber != "" && accountName != ""){
				$("#affirm").attr("disabled",true)
				$.ajax({
					type:"post",
// 					data:param,
					data:JSON.stringify(param),
					dataType: "json",
					contentType:"application/json",
					url:"${ctx}/tradeList/recharge",
					success:function(data){
						console.log(data)
						if(data.success==true){
							layer.alert('充值成功！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
								closeWin();
								layer.close(index);
							});
						}else{
							layer.alert('充值失败！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
								$("#affirm").attr("disabled",false)
								layer.close(index);
							});
						};
						
					},
					error:function(msg){
						//console.log(msg)
						$("#affirm").attr("disabled",false)
						layer.alert("请检查您的网络连接，然后重试！");
					}
				});
			}else{
				layer.alert("请填写完整信息并注意金额填写数字且不能为0");
			};
			
		});
		//弹出框 点击取消
		$("#cancel").click(function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);//关闭弹出的子页面窗口  
		});
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		function closeWin(){
			 parent.layer.close(index);
		}
		
	});
</script>
</head>
<body>
				
					<table class="rechargeContent"> 
						<tr><td class="small">金额：</td><td><input class="money" id="money" type="text" placeholder="请输入金额"/></td></tr>
						<tr><td class="small">账号：</td><td><input class="money" id="accountNumber" type="text" placeholder="请输入账号"/></td></tr>
						<tr class="spec"><td>账户名称：</td><td><input class="money" id="accountName" type="text" placeholder="请输入账户名称"/></td></tr>
					</table>
					<button class="add_minus" id="affirm" style="margin-left:170px;float:left;">确认</button>
					<button class="backOne" id="cancel" style="margin-left:20px;float:left;">取消</button>
</body>
</html>